/**
 *
 * _.fromPairs([['a', 1], ['b', 2]]);
 * // => { 'a': 1, 'b': 2 }
 */
export function fromPairs(pairs: [string, any][]): Record<string, any> {
  const length = pairs == null ? 0 : pairs.length
  const result = {};

  for (let i = 0; i < length; i++) {
    let pair = pairs[i];
    result[pair[0]] = pair[1];
  }
  return result;
}

/**
 *
 * _.toPairs({ 'a': 1, 'b': 2 });
 * // => [['a', 1], ['b', 2]]
 */
export function toPairs(obj: Record<string, any>): [string, any][] {
  if (obj == null) return []
  const result: [string, any][] = [];
  for (const key in obj) {
    if (obj.hasOwnProperty(key)) {
      result.push([key, obj[key]])
    }
  }

  return result;
}

